/* (C) C.D.F. Miller, Heriot-Watt University, March 1984
 *
 *	Permission is hereby given to reproduce or modify this
 *	software freely, provided that this notice be retained,
 *	and that no use be made of the software for commercial
 *	purposes without the express written permission of the
 *	author.
 */

/* actions.c:
 *	keyword action routines
 */

#include	<lbl.h>
#include	<ctype.h>
#include        <string.h>
#include        <stdlib.h>
#include        <err.h>
#include        "build.h"
#include        "find.h"

extern char *def_format;
extern int sflag;
extern FILE *tempfile;

void a_delimiter(int nargs, char *argvec[]);
/*ARGSUSED*/
void
a_delimiter(int nargs, char *argvec[])
{
	(void)nargs;
	if (strcmp(argvec[1], "off") == 0) {
		if (!sflag)
			fprintf(tempfile, "%c%c%c\n", MAGIC1, MAGIC2, M_DELIM);
		return;
	}
	if (argvec[1][1] != '\0') {
		warnx("%sdelimiter more than 1 character", maybe_loc());
		return;
	}
	if (argvec[1][0] == '\0') {
		warnx("%snull delimiter character", maybe_loc());
		return;
	}
	if (!sflag)
		fprintf(tempfile, "%c%c%c%c\n", MAGIC1, MAGIC2,
		        M_DELIM, argvec[1][0]);
}

void a_format(int nargs, char *argvec[]);
/*ARGSUSED*/
void
a_format(int nargs, char *argvec[])
{
	Type *tp = findtype(argvec[1], 1);

	(void)nargs;
	if (tp->t_format != def_format)
		warnx("%s[warning] format for %s redefined", maybe_loc(), tp->t_name);
	tp->t_format = copy(argvec[2]);
}

void a_last(int nargs, char *argvec[]);
/*ARGSUSED*/
void
a_last(int nargs, char *argvec[])
{
	Type *tp = findtype(argvec[1], 1);
	int indx;

	nargs -= 2;
	argvec += 2;
	for (indx = 0; indx < nargs; indx++) {
		if (!isdigit(argvec[indx][0])) {
			warnx("%snon-numeric label index", maybe_loc());
			break;
		}
		tp->t_levels[indx] = atoi(argvec[indx]);
	}
	while (indx < NLEVELS)
		tp->t_levels[indx++] = 0;
}
